#include <iostream>

using namespace std;
#include<ifactory.h>
#include<iproduct.h>
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if(p) {delete(p); (p) = nullptr;} }
#endif
int main()
{
    IFactory *pFactory=IFactory::CreateFactory(IFactory::FACTORY_A);
    IProductA *pA=pFactory->CreateProductA();
    IProductB *pB=pFactory->CreateProductB();
    cout<<pA->Name()<<endl;
    cout<<pB->Name()<<endl;

    SAFE_DELETE(pA);
    SAFE_DELETE(pB);

    pFactory=IFactory::CreateFactory(IFactory::FACTORY_B);
    pA=pFactory->CreateProductA();
    pB=pFactory->CreateProductB();
    cout<<pA->Name()<<endl;
    cout<<pB->Name()<<endl;
    SAFE_DELETE(pA);
    SAFE_DELETE(pB);

    pFactory=IFactory::CreateFactory(IFactory::FACTORY_C);
    pA=pFactory->CreateProductA();
    pB=pFactory->CreateProductB();
    cout<<pA->Name()<<endl;
    cout<<pB->Name()<<endl;
    SAFE_DELETE(pA);
    SAFE_DELETE(pB);

    return 0;
}
